package com.yilu.driver.mvp.model;

import com.is.common.retrofitrxcache.RxCacheResult;
import com.is.common.rx.RxSchedulers;
import com.yilu.driver.api.DriverApi;
import com.yilu.driver.base.Retrofit2Driver;
import com.yilu.driver.entity.DeleteTraineeResponse;
import com.yilu.driver.entity.TraineeDropResponse;
import com.yilu.driver.entity.TraineeInfoResponse;
import com.yilu.driver.mvp.contract.TraineeInfoContract;

import org.json.JSONObject;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @author Administrator
 * @date 2017/4/12 0012
 */

public class TraineeInfoModel implements TraineeInfoContract.Model {
    /**
     * 获取学员详情
     */
    @Override
    public Observable<RxCacheResult<TraineeInfoResponse>> getTraineeInfo(JSONObject json) {
        return Retrofit2Driver.getDefault(DriverApi.class)
                .getTraineeInfo(json.toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxSchedulers.<RxCacheResult<TraineeInfoResponse>>io_main());
    }

    /**
     * 退学
     *
     * @param json
     * @return
     */
    @Override
    public Observable<RxCacheResult<TraineeDropResponse>> dropOutTrainee(JSONObject json) {
        return Retrofit2Driver.getDefault(DriverApi.class)
                .dropOutTrainee(json.toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxSchedulers.<RxCacheResult<TraineeDropResponse>>io_main());
    }

    /**
     * 删除学员
     *
     * @param json
     * @return
     */
    @Override
    public Observable<RxCacheResult<DeleteTraineeResponse>> deleteTrainee(JSONObject json) {
        return Retrofit2Driver.getDefault(DriverApi.class)
                .deleteTrainee(json.toString())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxSchedulers.<RxCacheResult<DeleteTraineeResponse>>io_main());
    }
}
